{% extends 'LimsMainBundle::Layout/formLayout.html.twig' %}

{% block stylesheets %}
    {{ parent() }}
    <link href="/template/css/lims/inquiry.css" rel=stylesheet type=text/css />
{% endblock %}

{% block javascripts %}
    {{ parent() }}    
    <script type=text/javascript src="/template/js/lims/inquiry.js"></script>
 {#    <script type=text/javascript src="/template/js/plugins/knob/jquery.knob.js"></script>
    <script type=text/javascript src="/template/js/plugins/sparkline/jquery.sparkline.min.js"></script>
    <script type=text/javascript src="/template/js/plugins/flot/jquery.flot.js"></script>#}
    
{% endblock %}

{% block content %}

    {% include 'LimsMainBundle::Breadcrumb/breadcrumb.html.twig' with {'breadCrumbName' : 'Зээлдэгч иргэний лавлагаа'} %} 
    
    <div class="row">         
        <div class="col-md-12"> 
            
            <div id="inquiryContainerWrapper" class="inquiryContainerWrapper">
                
                <table class="border-none">
                    
                    <tr>
                        <td rowspan="2" style="width: 200px;padding: 10px;">
                            <div style="border: 1px solid #ccc;width: 100px;height: 150px;vertical-align: middle;"></div>
                        </td>
                        <td style="padding: 30px 0px 0px 100px;"><h1>LIMS Зээлийн мэдээллийн сан</h1></td>
                    </tr>
                    <tr>
                        <td style="text-align: right"><i>"Зээлийн мэдээллийн тухай хууль" <br/> үндэслэн энэхүү лавлагааг гаргав</i></td>
                    </tr>
                
                </table>
                <hr/>
                <table>
                    <tr>
                        <td style="text-align: left;border: none;">{{date|date('Y-m-d')}}</td>
                        <td style="text-align: right;border: none;">Улаанбаатар</td>
                    </tr>
                </table>
                
                <table class="border-none" style="width: 700px;margin: 0 auto;">
                    <tr>
                        <td colspan="2" style="text-align: center">
                            <h3>Зээлдэгч иргэний лавлагаа</h3>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right;width: 130px;">Ургын овог : </td>
                        <td><b>{{inquiry.debtor.FAMILY_NAME|upper}}</b></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;width: 130px;">Овог : </td>
                        <td><b>{{inquiry.debtor.LAST_NAME|upper}}</b></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;width: 130px;">Нэр : </td>
                        <td><b>{{inquiry.debtor.FIRST_NAME|upper}}</b></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;width: 130px;">Гэрлэлтийн байдал : </td>
                        <td><b>{% if inquiry.debtor.IS_MARRIED == 1 %}Гэрэлсэн{% else %}Гэрлээгүй{% endif %}</b></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;width: 130px;">Утас : </td>
                        <td><b>{{inquiry.contact.PHONE_NUMBER}}</b>&nbsp;&nbsp;<a href="javascript: phoneHistory();" id="historyPhoneBtn" class="historyBtn">Түүх харах</a></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;width: 130px;">И-мэйл : </td>
                        <td><b>{{inquiry.contact.EMAIL}}</b> &nbsp;&nbsp;<a href="javascript: emailHistory();" id="historyEmailBtn" class="historyBtn">Түүх харах</a></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;width: 130px;">Хаяг : </td>
                        <td><b>{{inquiry.contact.ADDRESS}}</b> &nbsp;&nbsp;<a href="javascript: addressHistory();" id="historyAddressBtn" class="historyBtn">Түүх харах</a></td>
                    </tr>
                </table>
                
                <hr/>
                <h3>Зээлийн мэдээлэл</h3>
                
                <table>
                    <thead>
                        <tr>
                            <th style="width: 2%">
                                #
                            </th>
                            <th style="width: 20%">
                                Зээлийн төрөл
                            </th>
                            <th style="width: 9%">
                                Хэмжээ
                            </th>
                            <th style="width: 9%">
                                Хүү
                            </th>
                            <th style="width: 15%">
                                Нийт зээлийн хэмжээ
                            </th>
                            <th style="width: 10%">
                                Үлдэгдэл
                            </th>
                            <th style="width: 9%;">
                                Ангилал
                            </th>
                            <th style="width: 9%">
                                Төлөв
                            </th>
                            <th style="width: 17%">
                                Хугацаа
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr style="background-color: #f4f4f4">
                            <td colspan="9">Үндсэн зээлийн мэдээлэл</td>
                        </tr>
                        {% set counter = 1 %}
                        {% for credit in inquiry.credit %}
                        <tr>
                            <td>{{counter}}</td>
                            <td>{{credit.CREDIT_TYPE_NAME}}</td>
                            <td class="currency">{{credit.INITIAL_AMOUNT}}</td>
                            <td class="currency">{{credit.INTEREST_PERCENT}}</td>
                            <td class="currency">{{credit.TOTAL_AMOUNT}}</td>
                            <td class="currency">{{credit.TOTAL_BALANCE}}</td>
                            <td class="text-center">{{credit.QUALITY_NAME}}</td>
                            <td class="text-center">{{credit.STATUS_NAME}}</td>
                            <td>{{credit.DURATION | raw}}</td>
                        </tr>
                        {% set counter = counter + 1 %}
                        {% endfor %}
                        <tr style="background-color: #f4f4f4">
                            <td colspan="9">Хамтран зээлдэгчээр орсон зээлийн мэдээлэл</td>
                        </tr>
                        <tr>
                            <td>4</td>
                            <td>2</td>
                            <td>3</td>
                            <td>4</td>
                            <td>5</td>
                            <td>6</td>
                            <td>7</td>
                            <td>8</td>
                            <td>9</td>
                        </tr>
                    </tbody>
                </table>
                
                <hr style="margin-top:20px"/>
                <h3>Зээлийн график</h3>
                
                <table>
                    <thead>
                        <tr style="background-color: #f4f4f4">
                            <th style="width: 20%">
                                Нэр
                            </th>
                            <th style="width: 20%">
                                Хамрах огноо
                            </th>
                            <th style="width: 15%">
                                Хэмжээ
                            </th>
                            <th style="width: 10%">
                                Хүү
                            </th>
                            <th style="width: 20%">
                                Нийт төлөх зээлийн хэмжээ
                            </th>
                            <th style="width: 15%">
                                
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for schedule in inquiry.schedule %}
                        <tr>
                            <td>{{schedule.NAME}}</td>
                            <td>{{schedule.DURATION}}</td>
                            <td class="currency">{{schedule.INITIAL_AMOUNT}}</td>
                            <td class="currency">{{schedule.INTEREST_PERCENT}}</td>
                            <td class="currency">{{schedule.TOTAL_AMOUNT}}</td>
                            <td>
                                <a href="#graphicPopup" onclick="openGraph({{schedule.ID}})" class="btn btn-info btn-clean" type="button" data-toggle="modal" >Дэлгэрэнгүй</a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                
                <hr style="margin-top:20px"/>
                <h3>Зээл төлөлтийн график</h3>
                
                <table>
                    <thead>
                        <tr style="background-color: #f4f4f4">
                            <th>
                                Нэр
                            </th>
                            <th>
                                Хамрах огноо
                            </th>
                            <th>
                                Хэмжээ
                            </th>
                            <th>
                                Хүү
                            </th>
                            <th>
                                Нийт төлөх зээлийн хэмжээ
                            </th>
                            <th>
                                Үлдэгдэл
                            </th>
                            <th>
                                Төлөв
                            </th>
                            <th>
                                
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for payment in inquiry.payment %}
                        <tr>
                            <td>{{payment.NAME}}</td>
                            <td>{{payment.DURATION}}</td>
                            <td class="currency">{{payment.INITIAL_AMOUNT}}</td>
                            <td class="currency">{{payment.INTEREST_PERCENT}}</td>
                            <td class="currency">{{payment.TOTAL_AMOUNT}}</td>
                            <td class="currency">{{payment.TOTAL_BALANCE}}</td>
                            <td></td>
                            <td>
                                <a href="#paymentPopup" onclick="openPayment({{payment.ID}})" class="btn btn-info btn-clean" type="button" data-toggle="modal" >Дэлгэрэнгүй</a>
                            </td>
                        </tr>
                        {% endfor %}                    
                    </tbody>
                </table>
                
                <hr style="margin-top:20px"/>
                
                <table class="border-none">
                    <tr>
                        <td style="width: 100px;text-align: left">
                            {#<img src="{{ qrcode_data_uri('123456789', size=100, padding=10) }}" style="float: right"/>#}
                            barcode
                        </td>
                        <td style="text-align: right">{{year}} оны {{month}} сарын {{day}} өдрийн байдлаар</td>
                    </tr>
                </table>
                
            </div>
            
        </div>
    </div>

<div class="modal" id="graphicPopup" role="dialog" aria-labelledby="graphicPopup" aria-hidden="true">
    <div class=modal-dialog>
        <div class=modal-content>
            <div class=modal-header>
                <button type=button class=close data-dismiss=modal aria-hidden=true>&times;</button>
                <h4 class=modal-title>Зээлийн график</h4>
            </div>
            <div class="modal-body clearfix" id="graphicPopupContent">

                <table class="table table-bordered table-striped table-hover">
                    <thead> 
                        <tr> 
                            <th width="5%">#</th>                                                             
                            <th width="15%">Огноо</th> 
                            <th width="5%">Хоног</th> 
                            <th width="15%">ҮЗ төлбөр</th> 
                            <th width="15%">Хүү төлбөр</th> 
                            <th width="15%">Нийт төлбөр</th>
                            <th width="15%">Зээлийн үлдэгдэл</th>                                            
                        </tr> 
                    </thead>
                    <tbody id="graphicPopupTbody" class="graphicPopupTbody">                        
                    </tbody>
                </table>
            </div>

            <div class=modal-footer>
                <button type="button" class="btn btn-default btn-clean" data-dismiss="modal">Хаах</button>                    
            </div>
        </div>
    </div>
</div>
          
<div class="modal" id="paymentPopup" role="dialog" aria-labelledby="paymentPopup" aria-hidden="true">
    <div class=modal-dialog>
        <div class=modal-content>
            <div class=modal-header>
                <button type=button class=close data-dismiss=modal aria-hidden=true>&times;</button>
                <h4 class=modal-title>Зээлийн төлөлт</h4>
            </div>
            <div class="modal-body clearfix" id="paymentPopupContent">

                <table class="table table-bordered table-striped table-hover">
                    <thead> 
                        <tr> 
                            <th width="5%">#</th>                                             
                            <th width="10%">Огноо</th> 
                            <th width="5%">Хоног</th> 
                            <th width="15%">ҮЗ төлбөр</th> 
                            <th width="15%">Хүү төлбөр</th> 
                            <th width="15%">Нийт төлбөр</th>
                            <th width="15%">Төлөлт</th>
                            <th width="5%">Төлөв</th>
                            <th width="15%">Зээлийн үлдэгдэл</th>
                        </tr> 
                    </thead>
                    <tbody id="paymentPopupTbody" class="paymentPopupTbody">                        
                    </tbody>
                </table>
            </div>

            <div class=modal-footer>
                <button type="button" class="btn btn-default btn-clean" data-dismiss="modal">Хаах</button>                    
            </div>
        </div>
    </div>
</div>
{% endblock %}